<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!-- top-bar -->
<header class="top-barBox">
    <div class="top-bar">
        <div id="logo">
            <a href="/"><img src="assets/images/logo.png" alt="logo"></a>
            <p class="siteWord">——Blog分享，众乐乐肯定爽过独乐乐！</p>
            <p class="max414">—Blog分享，众乐乐!</p>
        </div>
        <div class="top-barR">
            <shiro:user>
            	<span class="min414">你好，<em id="userName"><shiro:principal></shiro:principal></em>!</span>
            	<span id="center"><a href="mgindex">个人中心</a></span>
            	<span><button type="button" id="logout" class="logout">退出</button></span>
            </shiro:user>
            <shiro:guest><span><a href="login">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="register">注册</a></span></shiro:guest>
        </div>
    </div>
</header>
<!-- top-bar -->
<!-- menu -->
<div class="menu-Box">
	<nav class="menu">
        <p id="menuBox">
        </p>
        <div class="selectB">
            <div class="select">
                <input class="select-text" id="searchText" type="text" placeholder="请输入标题名称"><a href="search" class="select-btn" id="search" type="button"></a>
            </div>
        </div>
    </nav>
</div>
<!-- menu -->
<script type="text/javascript" src="assets/scripts/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){
	$.get("getTags",function(data){
		$menuBox = $("#menuBox");
		var $index = $("<a href='/' data-tag='首页' >首页</a>");
		$menuBox.append($index);
		for(var i=0;i<data.length;i++){
			var $a = $("<a href='list?tag="+data[i]+"'>" + data[i] + "</a>");
			$menuBox.append($a);
		}
	});
	
	$("#menuBox").on("click","a",function(){
		if($(this).hasClass("click")){
			return false;
		}
	});
	
	$("#logout").click(function(){
		$.get("logout",function(data){
			if(data.res == true){
				alert("欢迎再次光临。");
				window.location.href='/';
			}
		});
	});
	
	$("#search").click(function(){
		if($("#searchText").val() == ""){
			return false;
		}else{
			search();
		}
	});
	$(document).keydown(function(event){  
  	  if(event.keyCode == 13 || event.keyCode == 108){  
  		if($("#searchText").val() == ""){
			return false;
		}else{
			search();
		}
  	  } 
  	}); 
	function search(){
		var $searchText = $("#searchText").val();
		$.get("searchPage?searchText="+$searchText,function(data){
			window.location.href="search";
		});
	}
});

</script>